/**
*  \file endian.h
*
*  \brief   Endian support functions.
*
*  \author  Michael J. Hohmann <michael.hohmann@linde-mh.de>
*  \author  J. Treisch         <joerg.treisch@linde-mh.de>
*
*
*/

#ifndef ENDIAN_H_INCLUDED
#define ENDIAN_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include "../cfg/endian_cfg.h"
#include "../xmem/xmem.h"
#include "../pal/pal_endian.h"
#include "../pal/pal_mem.h"

/*================================================[ public defines   ]================================================*/

/*================================================[ public datatypes ]================================================*/

/*================================================[ public variables ]================================================*/

/*================================================[ public functions ]================================================*/


/** Copy data to big endian.
*
*  \param dest Pointer to the source object.
*  \param src  Pointer to the destination object.
*  \param size Number of bytes to be copied.
*
*  \return Value of dest.
*/
STATIC_INLINE void ENDIAN_MEM_TYPE* endian_copy_to_big(void * dest, void const * src, U32 size )
{
#if PAL_ENDIAN == PAL_ENDIAN_BIG
   pal_memcpy( dest, src, (size_t) size );
   return dest;
#else
   pal_memcpy_reverse( dest, src, (size_t) size );
   return dest;
#endif
}


/** Copy data to little endian.
*
*  \param dest Pointer to the source object.
*  \param src  Pointer to the destination object.
*  \param size Number of bytes to be copied.
*
*  \return Value of dest.
*/
STATIC_INLINE void ENDIAN_MEM_TYPE* endian_copy_to_little(void * dest, void const * src, U32 size )
{
#if PAL_ENDIAN == PAL_ENDIAN_BIG
   pal_memcpy_reverse( dest, src, (size_t) size );
   return dest;
#else
   pal_memcpy( dest, src, (size_t) size );
   return dest;
#endif
}

/** Copy data from big endian.
*
*  \param dest Pointer to the source object.
*  \param src  Pointer to the destination object.
*  \param size Number of bytes to be copied.
*
*  \return Value of dest.
*/
STATIC_INLINE void ENDIAN_MEM_TYPE* endian_copy_from_big(void * dest, void const * src, U32 size )
{
#if PAL_ENDIAN == PAL_ENDIAN_BIG
   pal_mem_copy( dest, src, (size_t) size );
   return dest;
#else
   pal_memcpy_reverse( dest, src, (size_t) size );
   return dest;
#endif
}

/** Copy data from little big endian.
*
*  \param dest Pointer to the source object.
*  \param src  Pointer to the destination object.
*  \param size Number of bytes to be copied.
*
*  \return Value of dest.
*/
STATIC_INLINE void ENDIAN_MEM_TYPE* endian_copy_from_little(void * dest, void const * src, U32 size )
{
#if PAL_ENDIAN == PAL_ENDIAN_BIG
   pal_memcpy_reverse( dest, src, (size_t) size );
   return dest;
#else
   pal_memcpy( dest, src, (size_t) size );
   return dest;
#endif
}

/*====================================================================================================================*/

#endif
/***********************************************************************************************************************
*                             Copyright 2011 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
